home *** CD-ROM | disk | FTP | other *** search
- Path: oitnews.harvard.edu!cmcl2!news!schonberg!dewar
- From: dewar@cs.nyu.edu (Robert Dewar)
- Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c
- Subject: Re: Hungarian notation - whoops!
- Date: 2 Mar 1996 09:19:33 -0500
- Organization: Courant Institute of Mathematical Sciences
- Message-ID: <dewar.825776096@schonberg>
- References: <30C40F77.53B5@swsbbs.com> <4fc157$jsf@goanna.cs.rmit.EDU.AU> <dewar.823793746@schonberg> <4fms62$c0p@goanna.cs.rmit.EDU.AU> <4ft1ruINN6dr@keats.ugrad.cs.ubc.ca> <4g9255$74s@goanna.cs.rmit.EDU.AU> <824909942snz@genesis.demon.co.uk> <4h6gbp$guh@goanna.cs.rmit.EDU.AU>
- NNTP-Posting-Host: schonberg.cs.nyu.edu
- X-Newsreader: NN version 6.5.0 (NOV)
-
- Richard O'Keefe said
-
- "I have implemented multiple-precision arithmetic, and I must say I found
- 2s-complement a confounded nuisance. What I wanted, and what I used,
- was arithmetic on N-bit natural numbers with overflow. In short, what
- I wanted for multiple precision arithmetic was
- N-bit natural + N-bit natural -> N-bit natural + carry
- N-bit natural - N-bit natural -> N-bit natural + borrow
- N-bit natural x N-bit natural -> 2N-bit natural
- 2N-bit natural (/,%) N-bit natural -> N-bit natural, N-bit natural
- Interpreting any of these as signed gave rise to serious complications."
-
- This makes me think that you don't understand the point. What you say above
- is that for multiple-precision you need unsigned arithmetic, and that signs
- get in the way. But the whole point is that TWOS COMPLEMENT ARITHMETIC IS
- IDENTICAL TO UNSIGNED (for addition and subtraction).
-
- If you had trouble from 2s-complement arithmetic in this context, it must
- have been because you were confused ..
-
- Using sign-and-magnitued arithmetic for multiple-precision implementation
- is a real pain, and in fact most, but not all, S&M machines have separate
- unsigned arithmetic instructions (or I should say had, since S&M machines
- have for the most part disappeared from sight, and good riddence!)
-
- As for the claim that you don't have to check for overflow in negation,
- that's preetty much irrelevant in practice, since in a properly
- written program with reasonable types, there is no reason that the range
- of your data should correspond to machine ranges anyway.
-
- type x is range -10 .. + 10;
- type y is range -3 .. +7;
-
- type x requires no overflow check for negation, regardless of the
- underying representation on the machine, and type y requires an
- overflow check for negation, regardless of the underlying
- representation on the machine.
-
-